<%@ Page Language="C#" Title="Edit Page" MasterPageFile="~/Views/Shared/Template.Master" Inherits="IWS.SiteManager.Web.Views.LayoutView<IWS.SiteManager.Core.Model.Content>" %>
<asp:Content ID="Head1" ContentPlaceHolderID="HeadContent" runat="server">
	
	<!-- Load TinyMCE -->
	<script type="text/javascript" src="/content/tinymce/jscripts/tiny_mce/jquery.tinymce.js"></script>
	<%=string.Format("<script type=\"text/javascript\"> var keyupdatePermalink={0};</script>",(Model.ID == 0).ToString().ToLower()) %>
	<script type="text/javascript">
		$().ready(function() {
			//Events
			$('#changePermalink').click(function() {
				var text = $(this).html();
				if (text == "Accept") {
					keyupdatePermalink = false;
					var text = $("#Permalink").val();
					$("#spanPermalink").html(text);
					$("#Permalink").hide();
					$("#spanPermalink").show();
					$(this).html("Change");
				}
				else {
					//slide span left, slide input right.
					$("#spanPermalink").hide();
					$("#Permalink").show();
					$(this).html("Accept");
				}

				return false;
			});

			$('#Title').keyup(function() {
				if (keyupdatePermalink) {
					var current_value = this.value.replace(/ /g, '-').replace('.', '').replace(',', '').trim();
					$('#spanPermalink').html(current_value);
					$('#Permalink').val(current_value);
				}
			});

			$("#linkDetails").click(function() {
				var val = $(this).html();
				if (val == "Show More") {
					$(this).html("Show Less");
					$("#divExtraDetails").slideDown("normal");
				}
				else {
					$(this).html("Show More");
					$("#divExtraDetails").slideUp("normal");
				}

			});

			$("#SectionID").change(function() {
				$("#DefaultPage").attr("checked", false);
			});

			//			Defaults
			$("#Permalink").hide();
			$("#divExtraDetails").hide();



			$('textarea.tinymce').tinymce({
				// Location of TinyMCE script
				script_url: '/content/tinymce/jscripts/tiny_mce/tiny_mce.js',

				// General options
				theme: "advanced",
				plugins: "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

				// Theme options
				//unused save,newdocument,fontselect,fontsizeselect,|,forecolor,backcolor
				theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect",
				theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview",
				theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,ltr,rtl,|,fullscreen",
				theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template",
				theme_advanced_toolbar_location: "top",
				theme_advanced_toolbar_align: "left",
				theme_advanced_statusbar_location: "bottom",
				theme_advanced_resizing: true,

				// Example content CSS (should be your site CSS)
				//content_css: "/content/Site.css", // add this later. 

				// Drop lists for link/image/media/template dialogs
				template_external_list_url: "lists/template_list.js",
				external_link_list_url: "lists/link_list.js",
				external_image_list_url: "lists/image_list.js",
				media_external_list_url: "lists/media_list.js",

				// Replace values for the template plugin
				template_replace_values: {
					username: "Some User",
					staffid: "991234"
				}
			});
		});
	</script>
	<style type="text/css">
		.column_main {margin-left: 300px; width: auto; }
		.column_left {margin-left: -300px; width: 298px; float: left; }
		.column_right {float: left; width: 100%;}
	</style>
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<%
	//globals
	var options = ViewData["Options"] as List<SelectListItem>;

	var sectionID = Request["section"];

	if (!string.IsNullOrEmpty(sectionID) && !options.Select(o=>o.Value).Contains(sectionID))
	{
		SelectListItem item = new SelectListItem();
		item.Value = sectionID;
		item.Text = sectionID;

		options.Add(item);
	}
	
	var section_detail = ViewData["Section"] as IWS.SiteManager.Core.Model.Section;
%>

	<div class="breadcrumb">
		<%=Html.ActionLink("Administration", "Index", "Manage") %> -&gt; <%=Html.ActionLink("Sections", "Sections", "Manage") %> -&gt; <%=Html.ActionLink(IWS.SiteManager.Core.SiteManagerContext.Current.CurrentSection, "SectionView", "Manage", new { id = Model.SectionID }, null)%> -&gt; Editing <%=Model.Title %>
	</div>
	<h2>Editing <%=Model.Title %></h2>
    <%= Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") %>

    <% using (Html.BeginForm("EditContent", "Manage"))
		 {%>
      <p>
          <input type="submit" value="Save" />
      </p>
    <%= Html.Hidden("ID", Model.ID)%>
   <p>
		<label class="normal" for="Title">Title</label><br />
       <%= Html.TextBox("Title", Model.Title, new { style = "font-size: 1.7em; width: 100%;" })%>
       <%= Html.ValidationMessage("Title", "*")%>
       <br /><label for="Permalink">Permalink:</label>
       http://<%=IWS.SiteManager.Core.SiteManagerContext.Current.SiteHostName %>/View/<%=IWS.SiteManager.Core.SiteManagerContext.Current.CurrentSection %>/<span id="spanPermalink"><%=Model.Permalink %></span><%= Html.TextBox("Permalink", Model.Permalink, new { style="width: 50%;"})%> <a href="#" id="changePermalink">Change</a>
       <%= Html.ValidationMessage("Permalink", "*")%>
   </p>
   <p><a id="linkDetails" href="#">Show More</a></p>
   <div id="divExtraDetails">
		<div class="column_main">
			<div class="column_left">
	<%			 if (options != null)
				 {%>
					<p>
						 <label for="SectionID">Section:</label>
						 <br /><%= Html.DropDownList("SectionID", options)%>
						 <%= Html.ValidationMessage("SectionID", "*")%>
						 
						 <br /><%=Html.CheckBox("DefaultPage", (bool)ViewData["SectionDefault"])%> <label for="DefaultPage">Make this page default (for the section)</label>
					</p>
	<%				}%>
					<p>
						 <label for="Tags">Tags:</label>
						 <br /><%= Html.TextBox("Tags", Model.Tags)%>
						 <%= Html.ValidationMessage("Tags", "*")%>
					</p>
					<p>
						 <label for="ModifiedUtc">Modified UTC:</label>
						 <%= Html.Encode(Model.ModifiedUtc.ToString())%>
						 <br /><label for="CreatedUtc">Created UTC:</label>
						 <%= Html.Encode(Model.CreatedUtc.ToString())%>
					</p>
			</div>
			<div class="column_right">
				<div>
					<p>
						 <label for="MetaDescription">Override MetaDescription:</label>
						 <%= Html.TextBox("MetaDescription", Model.MetaDescription, new { style="width: 100%;"})%>
						 <%= Html.ValidationMessage("MetaDescription", "*")%>
					</p>
					<p>
						 <label for="MetaKeywords">Override MetaKeywords:</label>
						 <%= Html.TextBox("MetaKeywords", Model.MetaKeywords, new { style = "width: 100%;" })%>
						 <%= Html.ValidationMessage("MetaKeywords", "*")%>
					</p>
				</div>
			</div>
         <p>
             <label for="Head">Custom Head Section:</label>
             <%= Html.TextArea("Head", Model.Head, new { style = "width:100%; height: 100px;"})%>
             <%= Html.ValidationMessage("Head", "*")%>
         </p>
		</div>
		<div class="clear"></div>
	</div>
            <p>
                <label for="Body">Text:</label>
                <%= Html.TextArea("Body", Model.Body, new { @class = "tinymce", style="width:100%; height: 400px;" })%>
                <%= Html.ValidationMessage("Body", "*")%>
             		<!-- Some integration calls -->
						<a href="javascript:;" onmousedown="$('#Body').tinymce().show();">[Show]</a>
						<a href="javascript:;" onmousedown="$('#Body').tinymce().hide();">[Hide]</a>
						<a href="javascript:;" onmousedown="$('#Body').tinymce().execCommand('Bold');">[Bold]</a>
						<a href="javascript:;" onmousedown="alert($('#Body').html());">[Get contents]</a>
						<a href="javascript:;" onmousedown="alert($('#Body').tinymce().selection.getContent());">[Get selected HTML]</a>
						<a href="javascript:;" onmousedown="alert($('#Body').tinymce().selection.getContent({format : 'text'}));">[Get selected text]</a>
						<a href="javascript:;" onmousedown="alert($('#Body').tinymce().selection.getNode().nodeName);">[Get selected element]</a>
						<a href="javascript:;" onmousedown="$('#Body').tinymce().execCommand('mceInsertContent',false,'<b>Hello world!!</b>');">[Insert HTML]</a>
						<a href="javascript:;" onmousedown="$('#Body').tinymce().execCommand('mceReplaceContent',false,'<b>{$selection}</b>');">[Replace selection]</a>
            </p>
            <p>
                <input type="submit" value="Save" />
            </p>
    <% } %>
</asp:Content>
